﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Liberty.Application.ServiceMemberManagement;
using Liberty.Domain.ServiceMemberManagement;
using Liberty.Domain.CaseManagement;

using Peradigm.Framework.Domain.Parties;
using Peradigm.Framework.UI.Web;
using System.Xml.Linq;

namespace Liberty.UI.Service.CaseManagement.Controls
{
    public partial class CaseDetailView : AbstractLibertyControl
    {
        #region Constants
        private const string
             MSG_YES = "Yes",
             MSG_NO = "No",
             MSG_NONE = "N/A",
             SERVICE_MEMBER_URL = "~/ServiceMemberManagement/ServiceMemberView.aspx";
         
        #endregion

        #region Event Handlers
        public override void UpdateView()
        {
            Case aCase = this.Case;

            this.lnkServiceMemberRankAndName.Text = aCase.ServiceMember.CanonicalName;

            DateTime bornOn = DateTime.Parse(aCase.ServiceMember.BornOn.ToString());
            
            this.lblServiceMemberDateOfBirth.Text = bornOn.ToString("d MMMM, yyyy");

            //this.lblServiceMemberUnitAndBranch.Text = String.Format(
            //    "{0}, {1}",
            //    this.UnitAssignmentFrom(aCase.ServiceMember),
            //    this.BranchFrom(aCase.ServiceMember));



            SetInjuryValues();
            lblDateInjured.Text = aCase.DateOfInjury.ToString();
            lblFacility.Text = aCase.CurrentVisit.Facility.Name;

            lblDateMemberArrived.Text = aCase.CurrentVisit.ArrivalDate.ToString();

            if (aCase.CurrentVisit.FamilyIsPresent)
                lblFamilyPresent.Text = MSG_YES;
            else
                lblFamilyPresent.Text = MSG_NO;

            if (aCase.CurrentVisit.HasInvitationalTravelOrders)
                lblInvitationalOrders.Text = MSG_YES;
            else
                lblInvitationalOrders.Text = MSG_NO;

            if (aCase.CurrentVisit.MethodOfTravel != null)
                lblTravelMethod.Text = aCase.CurrentVisit.MethodOfTravel.ToString();
            else
                lblTravelMethod.Text = MSG_NONE;

            if (aCase.CurrentVisit.OriginOfTravel != null)
                lblCity.Text = aCase.CurrentVisit.OriginOfTravel.ToString();

            if (aCase.CurrentVisit.FamilyArrival != null)
                lblDateFamilyArrived.Text = aCase.CurrentVisit.FamilyArrival.ToString();

        }

        protected void Page_Load(object sender, EventArgs e)
        {
        }
        #endregion

        #region Methods
        #endregion

        #region Properties
        #endregion

        #region Private Methods
        private void SetInjuryValues()
        {
            List<Injury> injuries = (List<Injury>)this.Case.Injuries;

            for (int i = 0; i < injuries.Count; i++)
            {
                switch (i)
                {
                    case 0:
                        lblInjury1.Text = injuries[0].TypeOfInjury.ToString();
                        break;
                    case 1:
                        lblInjury2.Text = injuries[1].TypeOfInjury.ToString();
                        break;
                    case 2:
                        lblInjury3.Text = injuries[2].TypeOfInjury.ToString();
                        break;
                }
            }
        }

        private string BranchFrom(ServiceMember serviceMember)
        {
            if (serviceMember.Branch != null)
            {
                return serviceMember.Branch.DisplayString;
            }
            return String.Empty;
        }

        private string UnitAssignmentFrom(ServiceMember serviceMember)
        {
            if (serviceMember.UnitAssignment != null)
            {
                return serviceMember.UnitAssignment.Name;
            }
            return String.Empty;
        }

        protected void cmdSelectServiceMember_OnClick(object sender, EventArgs e)
        {
            ServiceMember servicemember = this.Case.ServiceMember;
            this.Model = servicemember;
            Response.Redirect(SERVICE_MEMBER_URL);           
        }
   
        #endregion

        #region Private Properties
        private Case Case
        {
            get
            {
                return (Case)this.Model;
            }
        }
        #endregion

        #region Construction and Finalization
        #endregion

        #region Data Elements      
        #endregion

      
}
}
